<?php
namespace App\Providers;

use SwoStar\Rpc\RpcServerPriovder as ServerPriovder;

/**
 *
 */
class RpcServerPriovder extends ServerPriovder
{
    protected $services;

    /**
     * 加载rpc配置信息
     */
    protected function provider()
    {
        //这里设置了获取consul的配置，是个闭包函数，底层调用判断到$this->services是个闭包函数，则会进行实例化
        $this->services = function($sname){
            $services = $this->app->make('consul-agent')->health($sname)->getResult();
            $address= [];

            foreach ($services as $key => $value) {
                $address[] = [
                    "host" => $value["Service"]["Address"],
                    "port" => $value["Service"]["Port"]
                ];
            }

            return $address;
        };
    }

    public function boot()
    {
        parent::boot();
    }
}
